package main;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import model.trajectory.TargetModel;

public class TargetGridMouseAdapter implements MouseListener {

	public TargetGridTable table;
	public TargetModel lastTargetSelected = null;
	
	public TargetGridMouseAdapter(TargetGridTable table)
	{
		this.table = table;
	}
	@Override
	public void mouseClicked(MouseEvent event) 
	{
		if(this.lastTargetSelected != null)
		{
			this.lastTargetSelected.setHighlighted(false);
		}
		
		int selectedRow = table.getSelectedRow();
		TargetModel target = (TargetModel) this.table.getModel().getValueAt(selectedRow, 0); 

		target.setHighlighted(true);
		this.lastTargetSelected = target;
		if(event.getButton() == MouseEvent.BUTTON3)
		{
	        TargetGridPopupMenu popup = new TargetGridPopupMenu(target);
	        popup.show(event.getComponent(), event.getX(), event.getY());
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		/*int selectedRow = table.getSelectedRow();
		TargetModel target = (TargetModel) this.table.getModel().getValueAt(selectedRow, 0); 
		target.isHighlighted = true;
		this.lastTargetSelected = target;*/
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
	

	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

}
